/****************************************************************************
    Kantaoke, a karaoke game made with BennuGD.
    Copyright (C) 2010 Joseba García Echebarria

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

#ifndef __DECLARES_INC__
#define __DECLARES_INC__

#define gamename 'Kantaoke'
#define song_font 'Droid Sans'

// There's a hard limit of 300 songs here
#ifndef MAX_ALLOWED_SONGS
  #define MAX_ALLOWED_SONGS 300
#endif

#define LINESLIMIT 100
#define SYLLABLESLIMIT 20

// Here we'll define the various platform limitations
#ifdef WII
  #define BPP                   16
  #define NO_VLC
  #define CRAPPY_FONTS
  #define exec(a,b,c,d)
  #define set_title(a)
  #define get_desktop_size(a,b) *a=640;*b=480
  #define load_image(a)         load_png(a)
  #define getenv(a)             ""
#endif

#ifdef WIN32
  #define CRAPPY_FONTS
  #define BPP                   16
#endif

#ifdef OSX
  #define get_desktop_size(a,b) *a=1024;*b=768
  #define BPP                   16
#endif

// This way we can set these values at compile-time
#ifndef BPP
  #define BPP                   32
#endif
#ifndef MAIN_FPS
  #define MAIN_FPS              40
#endif

// Transparent shadows are only supported on 32 bpp mode
#if BPP!=32
  #ifndef NO_REFLECTION
    #define NO_REFLECTION
  #endif
#endif

//Dummy print function, only functional when on debug mode
#ifdef DEBUG
  #define dbg_print(msg) say(msg)
#else
  #define dbg_print(msg)
#endif

// Replacement functions for when we cannot use Pango for font rendering
#ifdef CRAPPY_FONTS
  #define NATIVE_CHARSET        "CP850//TRANSLIT//IGNORE"
  #define pango_render(a)       write_in_map(font, a, 4)
  #define OPEN_HIGHLIGHT        ""
  #define CLOSE_HIGHLIGHT       ""
  #define OPEN_HIGHLIGHT_SMALL  ""
  #define CLOSE_HIGHLIGHT_SMALL ""
  #define OPEN_NOHIGHLIGHT      ""
  #define CLOSE_NOHIGHLIGHT     ""
  #define OPEN_COVER            ""
  #define CLOSE_COVER           ""
#else
  #define NATIVE_CHARSET        "UTF8//TRANSLIT"
  #define OPEN_HIGHLIGHT '<span font_family="'+song_font+'" weight="bold" font="20" color="#FFFF00" bgcolor="black">'
  #define CLOSE_HIGHLIGHT '</span>'
  #define OPEN_HIGHLIGHT_SMALL '<span font_family="'+song_font+'" weight="bold" font="15" color="#FFFF00" bgcolor="black">'
  #define CLOSE_HIGHLIGHT_SMALL '</span>'
  #define OPEN_NOHIGHLIGHT '<span font_family="'+song_font+'" weight="bold" font="20" color="#EEEEEE" bgcolor="black">'
  #define CLOSE_NOHIGHLIGHT '</span>'
  #define OPEN_NOHIGHLIGHT_SMALL '<span font_family="'+song_font+'" weight="bold" font="15" color="#EEEEEE" bgcolor="black">'
  #define CLOSE_NOHIGHLIGHT_SMALL '</span>'
  #define OPEN_COVER        '<span font_family="'+song_font+'" weight="bold" font="20" color="#FFFF00" bgcolor="black">'
  #define CLOSE_COVER       '</span>'
#endif

// Replacement functions in case we can use FMOD Ex (which is preferred)
#ifndef NO_FMOD
  #define _load_song(a)          fmodex_song_load(a)
  #define _play_song(a,b)        fmodex_song_play(a)
  #define _stop_song(a)          fmodex_song_stop(a)
  #define _is_playing_song(a)    fmodex_song_playing(a)
#else
  #define _load_song(a)          load_song(a)
  #define _play_song(a,b)        play_song(a, 0)
  #define _stop_song(a)          stop_song()
  #define _is_playing_song(a)    is_playing_song()
#endif

#define NOHIGHLIGHT_TEXT(str) OPEN_NOHIGHLIGHT+str+CLOSE_NOHIGHLIGHT
#define HIGHLIGHT_TEXT(str) OPEN_HIGHLIGHT+str+CLOSE_HIGHLIGHT

TYPE songs_list
  string title="";
  string artist="";
  string dirname="";
  string filename="";
  string coverpath="";
  string bgpath="";
  string music_file="";
  string charset="";
  int cover=0;
End;

//Syllable has the basic information of a lyrics syllable
TYPE syllable
  int activation_time=0;
  int deactivation_time=0;
  int tone=0;
  int activated=0;
  string text="";
End;

//Line type has the basic information of a line, as well as the first syllable of a line.
TYPE lyrics_line
  int appearance_time=0;
  int activation_time=0;
  int deactivation_time=0;
  int pid=0;
  int width=0;
  int visibility=0;
  string line_text="";
  syllable syllables[SYLLABLESLIMIT];
End;

//Song type includes the basic information for the song, as well as
//the pointer to the first line of lyrics.
TYPE song
  int bpm=0;
  int fd=0;
  int gap=0;
  int relative=0;
  int videogap=0;
  string artist="";
  string charset="";
  string title="";
  string coverpath="";
  string bgpath="";
  string video_file="";
  string music_file="";
  string license="";
  string url="";
  lyrics_line lines[LINESLIMIT];
End;

Global
  string datadir = "./", savegamedir = "", developerpath = gamename;
  string custompath = "HOME";
  float resx = 1024.0, resy=600.0;
  float vresx = 800.0, vresy = 600.0;   //Video resolution
  int desc_file_finished=0, dbid=0, songs_found=0, covers_rendered=0;
  songs_list songs[MAX_ALLOWED_SONGS];
#ifdef CRAPPY_FONTS
  int font=0;
#endif
End;

Local
  int die=0;
  float aux=0.0;
End;

/* main.prg */
Declare Process Main()
End

/* charset.inc */
Declare Function readchars(string pointer chars, string filename, int limit)
End
Declare Function string determine_charset(string filename)
End

/* misc.inc */
Declare Process robot()
End
Declare Process mouse_controller()
End
Declare Function string _trim(string str)
End
Declare Function string _ltrim(string str)
End
Declare Function string _rtrim(string str)
End
Declare Function create_dir_hierarchy(string new_directory)
End
Declare Function set_savegamepath()
End
Declare Function find_songs()
End
Declare Function render_cover(string coverpath, string title)
End
Declare Function pre_render_covers()
End

/* lyrics.inc */
Declare Function parse_file(string filename, song pointer kar)
End
Declare Function int ReadBeatFile(song pointer kar)
End
Declare Function int ReadBeat(int bpm, int fd, int pointer time,
            int pointer deact_time, int pointer tone, int gap, int videogap,
            string pointer lyrics)
End

/* playback.inc */
Declare Process rotate_cover(song kar, int delay)
End
Declare Process bottom_bar()
End
Declare Process announce_song(string song, string author, string license)
End
Declare Process display_lyrics_line(lyrics_line l)
End
Declare Process display_lyrics(song pointer kar)
End
Declare Process spectrum_analyser()
End
Declare Process play_file(string dirname, string filename)
End
Declare Function size_fullscreen(int graphic)
End
Declare Function resize_fullscreen(int pid)
End
Declare Function resize_maxvideo(int pid)
End

/* menu.inc */
Declare Process menu_rotate_cover(song kar, int delay)
End
Declare Process menu()
End
Declare Process no_songs_menu()
End
#endif
